package com.lzh.yupao.once;

import com.alibaba.excel.EasyExcel;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 导入星球用户到数据库
 * @author LZH
 * @date 2023/5/14
 */
public class ImportPlanetUser {
    public static void main(String[] args) {
        String fileName = "D:\\dev-vue-boot\\knowledge-planet\\yupao-backend\\src\\main\\resources\\testPlanetImport.xlsx";
        List<PlanetTableUserInfo> userInfoList =
                EasyExcel.read(fileName).head(PlanetTableUserInfo.class).sheet().doReadSync();

        System.out.println("总数 = " + userInfoList.size());

        Map<String, List<PlanetTableUserInfo>> listMap = userInfoList.stream()
                .filter(userInfo -> StringUtils.isNotEmpty(userInfo.getUsername()))
                .collect(Collectors.groupingBy(PlanetTableUserInfo::getUsername));

        for (Map.Entry<String, List<PlanetTableUserInfo>> entry : listMap.entrySet()) {
            if (entry.getValue().size() > 1) {
                System.out.println("username = " + entry.getKey());
            }
        }
        System.out.println("不重复的昵称数 = " + listMap);
    }
}
